//
//  BaseRoute.swift
//  ShopApp
//
//  Created by eme on 16/6/14.
//  Copyright © 2016年 eme. All rights reserved.
//

import Foundation
import Alamofire
import ModelProtocol
import CryptoSwift
import NetWorkCore

/// miker md5 加密
extension String {
    func getMd5Password() -> String {
        
        return "\(self)eme909014123561236jkwsdfjdw".md5()
    }
}

public enum UserApi{
    //  UserApi
    case login(username: String, password: String)
    /// 验证手机几号
    case checkphone(phone:String)
    /// 发送验证码
    case sendmsg(phone:String,type:String)
    /// 保存店铺注册信息
    case save(glshop:NSString)
    /// 重置密码
    case resetpwd(phone: String, password: String)
    /// 获取店铺对象
    case myshop
    /// 获取店铺对象（未登录）
    case getshop(spid: String)
    /// 注册第一节 下一步  验证邀请码 手机号等信息
    case regcheck(phone: String,code:String,type: String,aginvitecode:String)
    
    /// 校验手机短信验证码 用于忘记密码
    case checkcode(phone: String,code:String,type: String)
    /**
     update：2017年07月24日11:43:20
     不登录进入首页
     */
    /// 用户使用手机号,密码注册用户
    case regGlShopSimple(glshop:NSString)
    ///用户提交认证
    case saveAuthInfo(glshop:NSString)

}
extension UserApi: TargetType {
    
    //设置请求路径
    public var path: String {
        switch self {
        case .login:
            return "/login.json"
        case .checkphone:
            return "/cpUser/checkphone.json"
        case .sendmsg:
            return "/cpUser/sendmsg.json"
        case .save:
            return "/glShop/save.json"
        case .resetpwd:
            return "/cpUser/resetpwd.json"
        case .myshop:
            return "/glShop/a/myshop.json"
        case .getshop:
            return "/glShop/getshop.json"
        case .regcheck:
            return "/cpUser/regcheck.json"
        case .checkcode:
            return "/cpUser/checkcode.json"
        case .regGlShopSimple:
            return "/glShop/regGlShopSimple.json"
        case .saveAuthInfo:
            return "/glShop/saveAuthInfo.json"
        }
    }
    
    //设置请求方式 get post等
    public var method: HTTPMethod {
        switch self {
        default :
            return .post

        }
    }
    /// 设置请求参数
    public var parameters: Parameters? {
        switch self {
        case let .login(username, password):
            return ["username": username, "password": password.getMd5Password()]
        case let .checkphone(phone):
            return ["phone": phone]
        case let .sendmsg(phone,type):
            return ["phone": phone,"type":type]
        case let .save(glshop):
            return ["glShop": glshop]
        case let .getshop(spid):
            return ["spid": spid]
        case let .resetpwd(phone, password):
            return ["phone": phone, "password": password.getMd5Password()]
        case let .regcheck(phone,code,type,aginvitecode):
            return ["phone": phone,"code":code ,"type": type,"aginvitecode":aginvitecode]
        case let .checkcode(phone,code,type):
            return ["phone": phone,"code":code ,"type": type]
        case let .regGlShopSimple(glshop):
            return ["glShop": glshop]
        case let .saveAuthInfo(glshop):
            return ["glShop": glshop]
        default :
            return nil
        }
    }
    
}
